package cn.zhl.txt;

import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Set;

/**
 * @program: demos
 * @description:
 * @author: 刘振华
 * @create: 2020-11-04 11:42
 **/
public class SourceSql {
	private Set<String> sourceSet = new HashSet<>();

	@Test
	public void source()throws Exception{
		String path = "D:\\work\\文档\\3.塔里木\\数据库\\sql\\业务表.sql";

		BufferedReader bfr = new BufferedReader(new FileReader(path));
		String line = "";
		boolean flag = false;
		String fkStr = "";
		while ((line = bfr.readLine())!= null){
			if(line.startsWith("CREATE TABLE")){
				String tableName = line.split("\"")[3];
				if(sourceSet.contains(tableName)){
					System.out.println();
					System.out.print(tableName+"\t");
					flag = true;
				}
			}else {
				if(flag){
					if(line.startsWith("  \"")){
						String[] strs = line.split("\"");
						if(strs[1].startsWith("PK")){
							System.out.print(strs[1]+"\t");
						}else if(strs[1].startsWith("FK")){
							fkStr += strs[1]+",";
						}
					}
				}
				if(line.startsWith("DROP TABLE")){
					flag = false;
					if (fkStr.length() > 0) {
						System.out.print(fkStr.substring(0,fkStr.length()-1));
						fkStr = "";
					}
				}
			}
		}
		bfr.close();
	}

	@Before
	public void init(){

		sourceSet.add("CD_BAS_BOILER");
		sourceSet.add("CD_BAS_BOILER_INST");
		sourceSet.add("CD_BAS_BOILER_OTHER");
		sourceSet.add("CD_BAS_BOM_MANAGE");
		sourceSet.add("CD_BAS_BURNER");
		sourceSet.add("CD_BAS_CREEP_POINT");
		sourceSet.add("CD_BAS_CYLINDER");
		sourceSet.add("CD_BAS_CYLINDER_INST");
		sourceSet.add("CD_BAS_CYLINDER_NORM");
		sourceSet.add("CD_BAS_DATA_FILE");
		sourceSet.add("CD_BAS_DES_MAKE");
		sourceSet.add("CD_BAS_DOC_MANAGE");
		sourceSet.add("CD_BAS_ELEC_EQU");
		sourceSet.add("CD_BAS_ELEC_INST");
		sourceSet.add("CD_BAS_ELEC_OTHER");
		sourceSet.add("CD_BAS_EQU_ATTR_ADMIN");
		sourceSet.add("CD_BAS_EQU_ATTR_INST");
		sourceSet.add("CD_BAS_EQU_BOM");
		sourceSet.add("CD_BAS_EQU_RECORD");
		sourceSet.add("CD_BAS_EQU_SORT");
		sourceSet.add("CD_BAS_EQU_SORT_INST");
		sourceSet.add("CD_BAS_FAULT_CASE");
		sourceSet.add("CD_BAS_FAULT_CODE");
		sourceSet.add("CD_BAS_HEAD_NORM");
		sourceSet.add("CD_BAS_HEADER_SPECS");
		sourceSet.add("CD_BAS_HEAT_ANTISEPTIC");
		sourceSet.add("CD_BAS_HEATER");
		sourceSet.add("CD_BAS_HEATER_INST");
		sourceSet.add("CD_BAS_INHIBITOR");
		sourceSet.add("CD_BAS_INSTALL");
		sourceSet.add("CD_BAS_MACHINE_PERFORM");
		sourceSet.add("CD_BAS_PIPE_FITTING");
		sourceSet.add("CD_BAS_PIPELINE");
		sourceSet.add("CD_BAS_POINT_UWUTM");
		sourceSet.add("CD_BAS_RESPIRATOR");
		sourceSet.add("CD_BAS_RULE_MANAGE");
		sourceSet.add("CD_BAS_SAFE_ANNEX");
		sourceSet.add("CD_BAS_SAFE_FILE");
		sourceSet.add("CD_BAS_SAFE_INST");
		sourceSet.add("CD_BAS_SEAL_POINT");
		sourceSet.add("CD_BAS_SOCKET_NORM");
		sourceSet.add("CD_BAS_SOP_MANAGE");
		sourceSet.add("CD_BAS_SPECS_MATERIAL");
		sourceSet.add("CD_BAS_SUP_MANAGE");
		sourceSet.add("CD_BAS_SURFACE_TUBE");
		sourceSet.add("CD_BAS_TEST_INFO");
		sourceSet.add("CD_BAS_VESSEL");
		sourceSet.add("CD_BAS_VESSEL_INST");
		sourceSet.add("CD_BAS_VESSEL_OTHER");
		sourceSet.add("CD_BAS_VESSEL_PART");
		sourceSet.add("CD_BAS_VESSEL_PIPELINE");
		sourceSet.add("CD_BAS_VOLTAGE_TEST");
		sourceSet.add("CD_BAS_WELD_LINE");
		sourceSet.add("EQ_BAS_LINE_MANG");
		sourceSet.add("EQ_BAS_MAINTAIN_CARD");
		sourceSet.add("EQ_BAS_SPECIAL_TOOL");
		sourceSet.add("EQ_BAS_TECH_SPEC");
	}

}
